Microsoft XNA Framework Edition: Programming Windows Phone 7 by Charles Petzold
Author:Charles Petzold [Charles Petzold]
Language: eng
Format: epub, pdf
Tags: COMPUTERS / Programming / Microsoft Programming
ISBN: 9780735656680
Publisher: Microsoft Press
Published: 2010-12-14T16:00:00+00:00
Notice that the if statement in GetAllX checks that y is between Point1.Y and Point2.Y; it allows y values that equal Point1.Y but not those that equal Point2.Y. In other words, it defines the line to be all points from Point1 (inclusive) up to but not including Point2. This caution about what points are included and excluded comes into play when multiple lines and arcs are connected; it helps avoid the possibility of having duplicate x values in the collection.
Also notice that no special consideration is given to horizontal lines, that is, lines where Point1.Y equals Point2.Y and where a equals infinity. If that is the case, then the if statement in the method is never satisfied. A scan line never crosses a horizontal boundary line.
The next structure is similar but for a generalized arc on the circumference of a circle:
Example 9-27. XNA Project: Petzold.Phone.Xna File: ArcSegment.cs
using System; using System.Collections.Generic; using Microsoft.Xna.Framework; namespace Petzold.Phone.Xna { public struct ArcSegment : IGeometrySegment { readonly double angle1, angle2; public ArcSegment(Vector2 center, float radius, Vector2 point1, Vector2 point2) : this() { Center = center; Radius = radius; Point1 = point1; Point2 = point2; angle1 = Math.Atan2(point1.Y - center.Y, point1.X - center.X); angle2 = Math.Atan2(point2.Y - center.Y, point2.X - center.X); } public Vector2 Center { private set; get; } public float Radius { private set; get; } public Vector2 Point1 { private set; get; } public Vector2 Point2 { private set; get; } public void GetAllX(float y, IList<float> xCollection) { double sqrtArg = Radius * Radius - Math.Pow(y - Center.Y, 2); if (sqrtArg >= 0) { double sqrt = Math.Sqrt(sqrtArg); TryY(y, Center.X + sqrt, xCollection); TryY(y, Center.X - sqrt, xCollection); } } public void TryY(double y, double x, IList<float> xCollection) { double angle = Math.Atan2(y - Center.Y, x - Center.X); if ((angle1 < angle2 && (angle1 <= angle && angle < angle2)) || (angle1 > angle2 && (angle1 <= angle || angle < angle2))) { xCollection.Add((float)x); } } } }
Download
Microsoft XNA Framework Edition: Programming Windows Phone 7 by Charles Petzold.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Blood, Sweat, and Pixels by Jason Schreier(3485)
Dawn of the New Everything by Jaron Lanier(2687)
Godot 4 Game Development Cookbook by Jeff Johnson(2553)
The Art of Doom by Bethesda(2037)
Significant Zero by Walt Williams(1885)
Creative Character Design by Bryan Tillman(1842)
World of Warcraft Chronicle Volume 3 by Blizzard Entertainment(1659)
The Ultimate Roblox Book by David Jagneaux(1617)
Art Of Atari by Tim Lapetino(1566)
Pillars of Eternity Guidebook by Obsidian Entertainment(1539)
Dawn of the New Everything: Encounters with Reality and Virtual Reality by Jaron Lanier(1539)
1628927445Game by Unknown(1477)
Unreal Engine 4 Virtual Reality Projects by Kevin Mack(1472)
Mission Python by Sean McManus(1456)
Unreal Engine Virtual Reality Quick Start Guide by Jessica Plowman(1452)
The Ultimate Player's Guide to Minecraft by Stephen O'Brien(1421)
Learning D by 2015(1419)
Unity 2018 By Example by Alan Thorn(1392)
Road Games by Road Games(1369)
